import socket,os,json,struct
sk=socket.socket()
sk.connect(('127.0.0.1',8080))
buffer=4096
heads={
    'filepath':r'D:\下载',
    'filename':r'网站效果展示.mp4',
    'filesize':None
}
fpath=os.path.join(heads['filepath'],heads['filename'])
fsize=os.path.getsize(fpath)
heads['filesize']=fsize
msg=json.dumps(heads).encode('utf-8')
sk.send(struct.pack('i',len(msg)))
sk.send(msg)
with open(fpath,'rb') as f:
    while fsize:
        if fsize>=buffer:
            content=f.read(buffer)
            sk.send(content)
            fsize-=buffer
        else:
            content=f.read(fsize)
            sk.send(content)
            break
sk.close()